////
////  LoginViewController.swift
////
//
//import MKit
//
//class LoginViewController: BaseViewController {
//
//    private var mobile: String = ""
//    private var code: String = ""
//    private var timer: TimerManager?
//    
//    private lazy var tipsLabel: UILabel = {
//        let view = UILabel()
//        view.text = "手机快捷登陆"
//        view.font = 20.boldFont
//        view.textColor = UIColor.sysBlack
//        return view
//    }()
//    
//    private lazy var mobileTextField: ZMTextField = {
//        let textField = ZMTextField()
//        textField.placeholder = "请输入手机号码"
//        textField.clearButtonMode = .whileEditing
//        textField.tintColor = UIColor.theme
//        textField.font = 15.font
//        textField.keyboardType = .numberPad
//        textField.zm_maxLength = 11
//        textField.didValueChange = { [weak self] textField in
//            guard let `self` = self, let text = textField.text else {
//                return
//            }
//            self.mobile = text
//            self.loginHandler()
//        }
//        return textField
//    }()
//    
//    private lazy var sendCodeBtn: UIButton = {
//        let view = UIButton()
//        view.setTitle("获取验证码", for: .normal)
//        view.setTitleColor(UIColor.c999999, for: .normal)
//        view.titleLabel?.font = 15.font
//        view.isUserInteractionEnabled = false
//        view.contentHorizontalAlignment = .right
//        view.on.tap { [weak self] (btn) in
//            guard let `self` = self else { return }
//            self.requestGetCode()
//        }
//        return view
//    }()
//    
//    private lazy var lineView: UIView = {
//        let view = UIView()
//        view.backgroundColor = UIColor.line
//        return view
//    }()
//    
//    private lazy var codeTextField: ZMTextField = {
//        let textField = ZMTextField()
//        textField.placeholder = "请输入验证码"
//        textField.clearButtonMode = .whileEditing
//        textField.tintColor = UIColor.theme
//        textField.font = 15.font
//        textField.keyboardType = .numberPad
//        textField.didValueChange = { [weak self] textField in
//            guard let `self` = self, let text = textField.text else {
//                return
//            }
//            self.code = text
//            self.loginHandler()
//        }
//        return textField
//    }()
//    
//    private lazy var lineView1: UIView = {
//        let view = UIView()
//        view.backgroundColor = UIColor.line
//        return view
//    }()
//    
//    private lazy var loginBtn: UIButton = {
//        let view = UIButton()
//        view.setTitle("登陆", for: .normal)
//        view.setTitleColor(UIColor.white, for: .normal)
//        view.backgroundColor = UIColor.theme.alpha(0.5)
//        view.titleLabel?.font = 15.font
//        view.isUserInteractionEnabled = false
//        view.corner(radii: 22.fit)
//        view.on.tap { [weak self] _ in
//            guard let `self` = self else { return }
//            self.requestLogin()
//        }
//        return view
//    }()
//    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        
//        setupNav()
//        addSubviews()
//    }
//    
//    private func setupNav() {
//        navigation.bar.alpha = 0
//    }
//
//    private func addSubviews() {
//        
//        view.addSubview(tipsLabel)
//        view.addSubview(mobileTextField)
//        view.addSubview(sendCodeBtn)
//        view.addSubview(lineView)
//        view.addSubview(codeTextField)
//        view.addSubview(lineView1)
//        view.addSubview(loginBtn)
//    
//        tipsLabel.snp.makeConstraints { (make) in
//            make.top.equalTo(topLayoutGuideBottom).offset(20.fit)
//            make.left.equalToSuperview().offset(15.fit)
//        }
//        
//        mobileTextField.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(12.fit)
//            make.top.equalToSuperview().offset(UIApplication.shared.navigationBarHeight + 100.fit)
//            make.right.equalToSuperview().offset(-150.fit)
//            make.height.equalTo(30.fit)
//        }
//        
//        sendCodeBtn.snp.makeConstraints { (make) in
//            make.centerY.equalTo(mobileTextField.snp.centerY)
//            make.right.equalToSuperview().offset(-12.fit)
//            make.height.equalTo(30.fit)
//            make.width.equalTo(120.fit)
//        }
//        
//        lineView.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(12.fit)
//            make.right.equalToSuperview().offset(-12.fit)
//            make.top.equalTo(mobileTextField.snp.bottom).offset(10.fit)
//            make.height.equalTo(0.5)
//        }
//        
//        codeTextField.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(12.fit)
//            make.top.equalTo(lineView.snp.bottom).offset(30.fit)
//            make.right.equalToSuperview().offset(-150.fit)
//            make.height.equalTo(30.fit)
//        }
//        
//        lineView1.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(12.fit)
//            make.right.equalToSuperview().offset(-12.fit)
//            make.top.equalTo(codeTextField.snp.bottom).offset(10.fit)
//            make.height.equalTo(0.5)
//        }
//        
//        loginBtn.snp.makeConstraints { (make) in
//            make.left.equalToSuperview().offset(12.fit)
//            make.right.equalToSuperview().offset(-12.fit)
//            make.top.equalTo(lineView1.snp.bottom).offset(30.fit)
//            make.height.equalTo(44.fit)
//        }
//    }
//    
//    private func loginHandler() {
//        if Matcher.phone.evaluate(mobile) {
//            sendCodeBtn.setTitleColor(UIColor.theme, for: .normal)
//            sendCodeBtn.isUserInteractionEnabled = true
//        } else {
//            sendCodeBtn.setTitleColor(UIColor.c999999, for: .normal)
//            sendCodeBtn.isUserInteractionEnabled = false
//        }
//        
//        if code.isEmpty {
//            loginBtn.backgroundColor = UIColor.theme.alpha(0.5)
//            loginBtn.isUserInteractionEnabled = false
//        } else {
//            loginBtn.backgroundColor = UIColor.theme
//            loginBtn.isUserInteractionEnabled = true
//        }
//    }
//
//    private func countDown() {
//        let timer = TimerManager()
//        timer.schedule(second: 120, surplus: { [weak self] (count) in
//            guard let `self` = self else { return }
//            DispatchQueue.main.async {
//                self.configSendBtn(true)
//                self.sendCodeBtn.setTitle("再次获取(\(count)s)", for: .normal)
//            }
//        }) {
//            DispatchQueue.main.async {
//                self.configSendBtn(false)
//                self.sendCodeBtn.setTitle("重新发送", for: .normal)
//            }
//        }
//        self.timer = timer
//    }
//    
//    private func configSendBtn(_ isSend: Bool) {
//        sendCodeBtn.isUserInteractionEnabled = !isSend
//        sendCodeBtn.setTitleColor(isSend ? UIColor.c999999 : UIColor.theme, for: .normal)
//    }
//}
//
//extension LoginViewController {
//    private func requestGetCode() {
//        Toast.loading()
//        Network.Login
//            .getCode(mobile: mobile)
//            .request()
//            .responseData(String.self) { [weak self] (model) in
//                guard let `self` = self else { return }
//                Toast.show(info: "验证码发送成功")
//                self.countDown()
//        } failure: { (error) in
//            Toast.show(info: error.errorMessage)
//        }
//    }
//    
//    private func requestLogin() {
//        Toast.loading()
//        Network.Login
//            .login(userAccount: mobile, password: code)
//            .request()
//            .responseData(LoginModel.self) { [weak self] (model) in
//                guard let `self` = self else { return }
//                LoginService.default.save(model.result)
//                Toast.show(info: "登陆成功")
//                DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
//                    guard let `self` = self else { return }
//                    self.goBack()
//                }
//        } failure: { (error) in
//            Toast.show(info: error.errorMessage)
//        }
//    }
//}
//
//extension LoginViewController {
//    
//}
